package com.woniuxy.propertyjava.controller;

import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.Payment;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class PaymentController {
    @Autowired
    PaymentService paymentService;
    @PostMapping("/payment/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<Payment>> getAllPayment(@PathVariable("pageIndex") int pageIndex,
                                                           @PathVariable("pageSize") int pageSize,
                                                           @RequestBody Payment payment){
        PageBean<Payment> pageBean=paymentService.getPaymentByPage(pageIndex, pageSize, payment);
        return new ResponseResult<>(200, "ok", pageBean);
    }

    @PostMapping("/payment")
    public ResponseResult<Payment> addPayment(@RequestBody Payment payment){
        System.out.println("添加报修："+payment);
        paymentService.insertPayment(payment);
        return new ResponseResult<>(200, "ok",null);
    }

    @PutMapping("/payment")
    public ResponseResult<Payment> modifyPayment(@RequestBody Payment payment){
        System.out.println("修改报修："+payment);
        paymentService.updatePayment(payment);
        return new ResponseResult<>(200, "ok",null);
    }

    @DeleteMapping("/payment/{paymentid}")
    public ResponseResult<Payment> removePayment(@PathVariable("paymentid") int paymentid){
        System.out.println("删除报修："+paymentid);
        paymentService.deletPayment(paymentid);
        return new ResponseResult<>(200, "ok",null);
    }
}
